package getsmart.project.mailsender;

import getsmart.project.database.DBProfil;
import getsmart.project.database.LogActivity;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.ArrayList;

import android.content.Context;

public class LogCreator {
	// Kelas untuk membuat log
	public String LogContent="";
	
	public String[] createLog(Context ctx, LogActivity logAct){
		String[] text = makeText(logAct);
		String[] filenameList = new String[text.length];
		for (int i=0; i<text.length; i++){
			try {            
				String filename="Log User "+i+".log";
				filenameList[i]=filename;
	            FileOutputStream fOut = ctx.getApplicationContext().openFileOutput(filename,Context.MODE_PRIVATE);
	            OutputStreamWriter osw = new OutputStreamWriter(fOut); 
	            osw.write(text[i]);
	            osw.flush();
	            osw.close();	
			} catch (IOException ioe) {
				ioe.printStackTrace();
			}
		}
		return filenameList;
	}
	
	private String[] makeText(LogActivity logAct){
		ArrayList<ArrayList<Object>> dataLog = logAct.getLog();
		ArrayList<ArrayList<Object>> dataProf = logAct.getLog();
		
		String[] result = new String[dataProf.size()];
		
		for (int i=0; i<dataProf.size(); i++){
			result[i]="User : "+(String) dataProf.get(i).get(1)+"\nTanggal Kegiatan\n";
			for (int j=0; j<dataLog.size(); j++){
				if(dataLog.get(j).get(1)==dataProf.get(i).get(0)){
					result[i]+=dataLog.get(j).get(2)+" "+dataLog.get(j).get(3)+"\n";
				}
			}
		}
		
		return result;
	}
	
}
